﻿//
//  Monkey Manager
//  Copyright (C) 2012 Victor Tereschenko
//
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//     
// ========================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using MonkeyManager.Command;

namespace MonkeyManager
{
    public partial class ManagerWindow : Window
    {
        class AutotagCommandStrategy
        {
            public AutotagCommandStrategy(AutotagCommand command, ManagerWindow window)
            {
                mWindow = window;
                command.AutotagCompleted += new EventHandler<AutotagItemCompletedEventArgs>(command_AutotagCompleted);
                command.Finish += new EventHandler<AutotagFinishEventsArgs>(command_Finish);
                command.Start += new EventHandler<AutotagStartEventsArgs>(command_Start);
            }

            void command_AutotagCompleted(object sender, AutotagItemCompletedEventArgs e)
            {
                mWindow.Dispatcher.Invoke((Action)(() =>
                {
                    mController.Increment();
                }));
            }

            ManagerWindow mWindow;
            ProgressBarController mController;

            void command_Start(object sender, AutotagStartEventsArgs e)
            {
                mWindow.Dispatcher.Invoke((Action)(() =>
                {
                    mController = new ProgressBarController(mWindow.grid.RowDefinitions[1], mWindow.progressBars, e.Files.Length);
                    mController.Show();
                }));
            }

            void command_Finish(object sender, AutotagFinishEventsArgs e)
            {
                mWindow.Dispatcher.Invoke((Action)(() =>
                {
                    mController.Close();
                    mController.Hide();
                    mWindow.mDataProvider.Request(mWindow.mFilter);
                }));
            }
        }
    }
}
